package com.ms.qw.server.infrastructure.persistence.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Properties;

/**
 * User: allona
 * Date: 09/03/12
 */
public class ApplicationProperties {

    private final static Logger logger = LoggerFactory.getLogger(ApplicationProperties.class);

    private static Properties props = null;

    private static String appResourcePath= "META-INF/spring/application.properties";

    public static Properties getAppPorperties() {

        if(props==null){
            try {
                props = ResourceProperties.getResourcePorperties(appResourcePath);
            } catch (IOException e) {
                logger.error("Error al leer el archivo de propiedades "+appResourcePath,e);
            }
        }
        return  props;
    }

    public static String getEmailFrom() {

        return  getAppPorperties().getProperty("mail.username");
    }

    public static String getDirectorio() {

        return  getAppPorperties().getProperty("dir.base");
    }

    public static String getEmailErrorTo(){

        return  getAppPorperties().getProperty("mail.error.to");
    }

    public static String getExcelTemplatePath() {

        return  getAppPorperties().getProperty("report.excel.template.path");
    }

    public static String getSmtpHost() {

        return  getAppPorperties().getProperty("mail.server.host");
    }

    public static String getSmtpHostPort() {

        return  getAppPorperties().getProperty("mail.server.port");
    }

    public static String getSmtpHostAuthFlag() {

        return  getAppPorperties().getProperty("mail.smtp.auth");
    }

    public static String getSmtpHostStart() {

        return  getAppPorperties().getProperty("mail.smtp.starttls");
    }

    public static String getSellAccountCode() {

        return  getAppPorperties().getProperty("sell.account.code");
    }

    public static String getSalaryAccountCode() {

        return  getAppPorperties().getProperty("salary.account.code");
    }


    public static String getApplicationCode() {

        return  getAppPorperties().getProperty("application.code");
    }
    public static String getUrlHost() {
        return  getAppPorperties().getProperty("url.host");
    }
    public static String getApplicationPlusPetrolPPN() {

        return  getAppPorperties().getProperty("application.pluspetrol.rucppn");
    }

    public static String getApplicationPlusPetrolPPC() {

        return  getAppPorperties().getProperty("application.pluspetrol.rucppc");
    }

    public static String getProperty(String propertyCode) {

        return  getAppPorperties().getProperty(propertyCode);
    }

    public static BigDecimal getFactorIndicator() {
        String factor=getAppPorperties().getProperty("egyp.factor.indicator");

        return new BigDecimal(factor);
    }

    public static Long getInvertvalUpdate() {
        String interval=getAppPorperties().getProperty("application.interval.update");

        return Long.valueOf(interval);
    }


}
